<<<<<<< HEAD
package com.wyz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wyz.common.AutoLog;
import com.wyz.common.ResultResponse;
import com.wyz.common.ResultVo;
import com.wyz.dto.StudentClassDTO;
import com.wyz.entity.ClassEntity;
import com.wyz.entity.StudentEntity;
import com.wyz.service.ClassService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wk
 * @desc
 * @date 2024/12/23 11:15
 */
@RestController
@Slf4j
@RequestMapping("/class")
public class ClassController {
    @Resource
    private ClassService classService;
    //分页查询所有班级
    @AutoLog("进入班级管理页面")
    @GetMapping("/queryClassByPage/{currentPage}")
    public ResultVo<Map<String,Object>> queryClassByPage(@PathVariable("currentPage") int currentPage){
        log.info("分页查询班级信息请求,参数:{}", currentPage);
        IPage<ClassEntity> classListPage = classService.getStudentListByPage(currentPage);
        List<ClassEntity> classList = classListPage.getRecords();//获取分页查询结果
        int total = (int)classListPage.getPages();//获取总页数
        //构造分页页码列表
        List<Integer> pageList = new ArrayList<>();
        for (int i = 1; i <= total ; i++) {
            pageList.add(i);
        }
        log.info("pageList:{}",pageList);

        //使用Map封装响应的多个数据
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("classList",classList);
        resultMap.put("pageList",pageList);

        log.info("获取分页图书列表响应", resultMap);

        return new ResultVo<>(200,"ok",resultMap);
    }
    //添加班级信息
    @AutoLog("添加班级信息")
    @PostMapping("/addClass")
    public ResultVo<String> addClass(@RequestBody ClassEntity classEntity){
        log.info("添加班级信息请求,参数:{}", classEntity);
        try {
            if (classService.addClass(classEntity)){
                log.info("添加班级信息成功:{}",classEntity);
                return ResultVo.success();
            }
            return ResultVo.fail();
        } catch (Exception e) {
            return ResultVo.fail();
        }
    }
    //通过id查询班级信息
    @AutoLog("通过id查询班级信息")
    @GetMapping("/queryClassById/{classId}")
    public ResultVo<ClassEntity> queryClassById(@PathVariable("classId") Integer classId){
        log.info("通过id查询班级信息请求,参数:{}", classId);
        ClassEntity classEntity = classService.queryClassById(classId);
        log.info("通过id查询班级信息响应,参数:{}", classEntity);
        return new ResultVo<>(200,"ok",classEntity);
    }
    //修改班级信息
    @AutoLog("修改班级信息")
    @PostMapping("/updateClass")
    public ResultVo<Boolean> updateClass(@RequestBody ClassEntity classEntity){
        log.info("修改班级信息请求,参数:{}", classEntity);
        try {
            boolean flag=classService.updateClass(classEntity);
            return new ResultVo<>(200,"ok",flag);
        } catch (Exception e) {
            return ResultVo.fail();
        }
    }
    //删除班级信息
    @AutoLog("删除班级信息")
    @GetMapping("/deleteClass/{classId}")
    public ResultVo<Boolean> deleteClass(@PathVariable("classId") Integer classId){
        log.info("删除班级信息请求,参数:{}", classId);

        try{
            boolean flag = classService.deleteClass(classId);
            return new ResultVo<>(200,"ok",flag);
        }catch (Exception e){
            return ResultVo.fail();
        }
    }
    //教师查询特定班级的学生名单和班级详情。
    @AutoLog("教师查询特定班级的学生名单和班级详情")
    @GetMapping("/queryStudentAndClass/{className}")
    public ResultVo<List<StudentClassDTO>> queryStudentAndClass(@PathVariable("className") String className){
        log.info("特定查询请求,参数:{}", className);
        List<StudentClassDTO> studentAndClassList =classService.queryStudentAndClassName(className);
        log.info("特定查询响应,参数:{}", studentAndClassList);
        return new ResultVo<>(200,"ok",studentAndClassList);
    }

}
=======
package com.wyz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wyz.common.AutoLog;
import com.wyz.common.ResultResponse;
import com.wyz.common.ResultVo;
import com.wyz.dto.StudentClassDTO;
import com.wyz.entity.ClassEntity;
import com.wyz.entity.StudentEntity;
import com.wyz.service.ClassService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wk
 * @desc
 * @date 2024/12/23 11:15
 */
@RestController
@Slf4j
@RequestMapping("/class")
public class ClassController {
    @Resource
    private ClassService classService;
    //分页查询所有班级
    @AutoLog("进入班级管理页面")
    @GetMapping("/queryClassByPage/{currentPage}")
    public ResultVo<Map<String,Object>> queryClassByPage(@PathVariable("currentPage") int currentPage){
        log.info("分页查询班级信息请求,参数:{}", currentPage);
        IPage<ClassEntity> classListPage = classService.getStudentListByPage(currentPage);
        List<ClassEntity> classList = classListPage.getRecords();//获取分页查询结果
        int total = (int)classListPage.getPages();//获取总页数
        //构造分页页码列表
        List<Integer> pageList = new ArrayList<>();
        for (int i = 1; i <= total ; i++) {
            pageList.add(i);
        }
        log.info("pageList:{}",pageList);

        //使用Map封装响应的多个数据
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("classList",classList);
        resultMap.put("pageList",pageList);

        log.info("获取分页图书列表响应", resultMap);

        return new ResultVo<>(200,"ok",resultMap);
    }
    //添加班级信息
    @AutoLog("添加班级信息")
    @PostMapping("/addClass")
    public ResultVo<String> addClass(@RequestBody ClassEntity classEntity){
        log.info("添加班级信息请求,参数:{}", classEntity);
        try {
            if (classService.addClass(classEntity)){
                log.info("添加班级信息成功:{}",classEntity);
                return ResultVo.success();
            }
            return ResultVo.fail();
        } catch (Exception e) {
            return ResultVo.fail();
        }
    }
    //通过id查询班级信息
    @AutoLog("通过id查询班级信息")
    @GetMapping("/queryClassById/{classId}")
    public ResultVo<ClassEntity> queryClassById(@PathVariable("classId") Integer classId){
        log.info("通过id查询班级信息请求,参数:{}", classId);
        ClassEntity classEntity = classService.queryClassById(classId);
        log.info("通过id查询班级信息响应,参数:{}", classEntity);
        return new ResultVo<>(200,"ok",classEntity);
    }
    //修改班级信息
    @AutoLog("修改班级信息")
    @PostMapping("/updateClass")
    public ResultVo<Boolean> updateClass(@RequestBody ClassEntity classEntity){
        log.info("修改班级信息请求,参数:{}", classEntity);
        try {
            boolean flag=classService.updateClass(classEntity);
            return new ResultVo<>(200,"ok",flag);
        } catch (Exception e) {
            return ResultVo.fail();
        }
    }
    //删除班级信息
    @AutoLog("删除班级信息")
    @GetMapping("/deleteClass/{classId}")
    public ResultVo<Boolean> deleteClass(@PathVariable("classId") Integer classId){
        log.info("删除班级信息请求,参数:{}", classId);

        try{
            boolean flag = classService.deleteClass(classId);
            return new ResultVo<>(200,"ok",flag);
        }catch (Exception e){
            return ResultVo.fail();
        }
    }
    //教师查询特定班级的学生名单和班级详情。
    @AutoLog("教师查询特定班级的学生名单和班级详情")
    @GetMapping("/queryStudentAndClass/{className}")
    public ResultVo<List<StudentClassDTO>> queryStudentAndClass(@PathVariable("className") String className){
        log.info("特定查询请求,参数:{}", className);
        List<StudentClassDTO> studentAndClassList =classService.queryStudentAndClassName(className);
        log.info("特定查询响应,参数:{}", studentAndClassList);
        return new ResultVo<>(200,"ok",studentAndClassList);
    }

}
>>>>>>> be516e15a35375b38cf973b1ce88c92dd1ceba03
